module.exports = app => {
    // const { Store } = require('koa-session2');
    const mongoose = app.mongoose;
    const connect = mongoose.connection;
    const collection = connect.collection('sessions');
    const dbUrl = 'mongodb://localhost/vcms';
    mongoose.connect(dbUrl,{
        useNewUrlParser: true,
        useUnifiedTopology: true,
        // useMongoClient: true
    });
    console.log('session start...')
    app.sessionStore = {
        async get(key) {
            let data = await collection.findOne({ key });
            console.log('15...', key, data);
		    return data;
        },
        async set(key, value, maxAge) {
            try {
                if(!key) {
                    key = this.getID(24);
                }
                console.log('22...', key, value);
                await collection.findOneAndUpdate({ key: key }, { $set: value }, { upsert: true });
            }catch(err) {
                console.log('error', error);
            }
            return key;
        },
        async destroy(key) {

        }
    }
}